package com.woniu.elderly.wares.controller;

import com.woniu.common.entity.Result;
import com.woniu.common.entity.WaresCategory;
import com.woniu.elderly.wares.service.WaresCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author: xuan
 * @Date: 2024/8/2 17:40
 * @Version: 1.0
 */
@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {
    @Autowired
    private WaresCategoryService categoryService;
    @GetMapping("/")
    public Result<List<WaresCategory>> getCategories() {
      // 调用categoryService的getCategories方法，获取商品分类列表
      List<WaresCategory> waresCategories =  categoryService.getCategories();
      // 构造Result对象，返回状态码200、成功信息"success"以及商品分类列表
      return new Result<>(200, "success", waresCategories);
    }
    @GetMapping("/{cid}")
    public Result<WaresCategory> getCategory(@PathVariable("cid") Integer cid) {
     log.info("进入查询,cid: {}", cid);
      // 调用categoryService的getById方法，根据cid获取商品分类信息
      WaresCategory waresCategory = categoryService.getById(cid);
      // 构造Result对象，返回状态码200、成功信息"success"以及商品分类信息
      return new Result<>(200, "success", waresCategory);
    }

}
